package c.e.a.b.f.b;

import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import b.i.b.f;
import c.f.d.a.a.b.d;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final class i4 {
    public final String a;
    public final Bundle b = new Bundle();
    public boolean c;
    public Bundle d;
    public final /* synthetic */ d4 e;

    public i4(d4 d4Var, String str) {
        this.e = d4Var;
        f.N(str);
        this.a = str;
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:34:0x009e */
    /* JADX WARNING: Can't wrap try/catch for region: R(3:34|35|46) */
    /* JADX WARNING: Missing block: B:35:?, code skipped:
            r12.e.d().f.a("Error reading value from SharedPreferences. Value dropped");
     */
    public final android.os.Bundle a() {
        /*
        r12 = this;
        r0 = r12.c;
        if (r0 != 0) goto L_0x00c7;
    L_0x0004:
        r0 = 1;
        r12.c = r0;
        r1 = r12.e;
        r1 = r1.w();
        r2 = r12.a;
        r3 = 0;
        r1 = r1.getString(r2, r3);
        if (r1 == 0) goto L_0x00bf;
    L_0x0016:
        r2 = new android.os.Bundle;	 Catch:{ JSONException -> 0x00b2 }
        r2.<init>();	 Catch:{ JSONException -> 0x00b2 }
        r3 = new org.json.JSONArray;	 Catch:{ JSONException -> 0x00b2 }
        r3.<init>(r1);	 Catch:{ JSONException -> 0x00b2 }
        r1 = 0;
        r4 = 0;
    L_0x0022:
        r5 = r3.length();	 Catch:{ JSONException -> 0x00b2 }
        if (r4 >= r5) goto L_0x00af;
    L_0x0028:
        r5 = r3.getJSONObject(r4);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r6 = "n";
        r6 = r5.getString(r6);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r7 = "t";
        r7 = r5.getString(r7);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r8 = -1;
        r9 = r7.hashCode();	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r10 = 100;
        r11 = 2;
        if (r9 == r10) goto L_0x005f;
    L_0x0042:
        r10 = 108; // 0x6c float:1.51E-43 double:5.34E-322;
        if (r9 == r10) goto L_0x0055;
    L_0x0046:
        r10 = 115; // 0x73 float:1.61E-43 double:5.7E-322;
        if (r9 == r10) goto L_0x004b;
    L_0x004a:
        goto L_0x0068;
    L_0x004b:
        r9 = "s";
        r9 = r7.equals(r9);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        if (r9 == 0) goto L_0x0068;
    L_0x0053:
        r8 = 0;
        goto L_0x0068;
    L_0x0055:
        r9 = "l";
        r9 = r7.equals(r9);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        if (r9 == 0) goto L_0x0068;
    L_0x005d:
        r8 = 2;
        goto L_0x0068;
    L_0x005f:
        r9 = "d";
        r9 = r7.equals(r9);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        if (r9 == 0) goto L_0x0068;
    L_0x0067:
        r8 = 1;
    L_0x0068:
        r9 = "v";
        if (r8 == 0) goto L_0x0096;
    L_0x006c:
        if (r8 == r0) goto L_0x008a;
    L_0x006e:
        if (r8 == r11) goto L_0x007e;
    L_0x0070:
        r5 = r12.e;	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r5 = r5.d();	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r5 = r5.f;	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r6 = "Unrecognized persisted bundle type. Type";
        r5.b(r6, r7);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        goto L_0x00ab;
    L_0x007e:
        r5 = r5.getString(r9);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r7 = java.lang.Long.parseLong(r5);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r2.putLong(r6, r7);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        goto L_0x00ab;
    L_0x008a:
        r5 = r5.getString(r9);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r7 = java.lang.Double.parseDouble(r5);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r2.putDouble(r6, r7);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        goto L_0x00ab;
    L_0x0096:
        r5 = r5.getString(r9);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        r2.putString(r6, r5);	 Catch:{ NumberFormatException | JSONException -> 0x009e, NumberFormatException | JSONException -> 0x009e }
        goto L_0x00ab;
    L_0x009e:
        r5 = r12.e;	 Catch:{ JSONException -> 0x00b2 }
        r5 = r5.d();	 Catch:{ JSONException -> 0x00b2 }
        r5 = r5.f;	 Catch:{ JSONException -> 0x00b2 }
        r6 = "Error reading value from SharedPreferences. Value dropped";
        r5.a(r6);	 Catch:{ JSONException -> 0x00b2 }
    L_0x00ab:
        r4 = r4 + 1;
        goto L_0x0022;
    L_0x00af:
        r12.d = r2;	 Catch:{ JSONException -> 0x00b2 }
        goto L_0x00bf;
    L_0x00b2:
        r0 = r12.e;
        r0 = r0.d();
        r0 = r0.f;
        r1 = "Error loading bundle from SharedPreferences. Values will be lost";
        r0.a(r1);
    L_0x00bf:
        r0 = r12.d;
        if (r0 != 0) goto L_0x00c7;
    L_0x00c3:
        r0 = r12.b;
        r12.d = r0;
    L_0x00c7:
        r0 = r12.d;
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.b.f.b.i4.a():android.os.Bundle");
    }

    public final void b(Bundle bundle) {
        if (bundle == null) {
            bundle = new Bundle();
        }
        Editor edit = this.e.w().edit();
        if (bundle.size() == 0) {
            edit.remove(this.a);
        } else {
            String str = this.a;
            JSONArray jSONArray = new JSONArray();
            for (String str2 : bundle.keySet()) {
                Object obj = bundle.get(str2);
                if (obj != null) {
                    try {
                        JSONObject jSONObject = new JSONObject();
                        jSONObject.put("n", str2);
                        jSONObject.put("v", String.valueOf(obj));
                        String str3 = "t";
                        if (obj instanceof String) {
                            jSONObject.put(str3, "s");
                        } else if (obj instanceof Long) {
                            jSONObject.put(str3, "l");
                        } else if (obj instanceof Double) {
                            jSONObject.put(str3, d.a);
                        } else {
                            this.e.d().f.b("Cannot serialize bundle value to SharedPreferences. Type", obj.getClass());
                        }
                        jSONArray.put(jSONObject);
                    } catch (JSONException e) {
                        this.e.d().f.b("Cannot serialize bundle value to SharedPreferences", e);
                    }
                }
            }
            edit.putString(str, jSONArray.toString());
        }
        edit.apply();
        this.d = bundle;
    }
}
